/*
 * Part of knowledge engineering (ke) course work, 2010/11
 */
package se.bth.ke.firstfriend.web;

import de.nixis.commons.web.base.Controller;
import java.util.List;
import javax.annotation.security.RolesAllowed;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.SecurityContext;
import org.springframework.stereotype.Component;
import se.bth.ke.firstfriend.model.BookmarkableItem;

/**
 *
 * @author nico
 */
@Component
@Path("/bookmark")
public class BookmarkController extends Controller {

    @PersistenceContext
    private EntityManager em;
    
    @GET
    @RolesAllowed("user")
    @Produces("text/html")
    public List<BookmarkableItem> list(@Context SecurityContext context) {
        return (List<BookmarkableItem>) em.createQuery("SELECT b FROM User u JOIN u.bookmarks b JOIN FETCH b.article WHERE u = :user")
                                  .setParameter("user", getActiveUser())
                                  .getResultList();
    }
}
